package com.vanke.devops.domain.manager.dingding.impl;

import com.vanke.core.util.RestClient;
import com.vanke.devops.domain.manager.dingding.DingDingManager;
import com.vanke.devops.domain.manager.dingding.bean.TextMsg;
import com.vanke.devops.domain.properties.DingDingProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author 陈景阳
 * @since 2018/6/6
 */
@Service
@EnableConfigurationProperties(DingDingProperties.class)
public class DingDingManagerImpl implements DingDingManager {

    @Autowired
    private DingDingProperties dingDingProperties;

    private RestClient restClient = new RestClient();

    @Override
    public void sendText(String text) {
        String url = dingDingProperties.getHost() + "?access_token=" + dingDingProperties.getAccessToken();
        TextMsg textMsg = new TextMsg(text);
        try {
            restClient.post(url,textMsg,Object.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
